﻿using System;

namespace Bubble_Sort
{
    public static class BubbleSort
    {
        private static int[] array;

        public static int[] Sort(int[] arr)
        {
            array = arr;
            BubbleSortHelper();

            return array;
        }

        private static void BubbleSortHelper()
        {
            bool continueLoop = true;
            int loops = array.Length - 1;

            while (continueLoop)
            {
                continueLoop = false;

                for (int i = 0; i < loops; i++)
                {
                    if (array[i] > array[i + 1])
                    {
                        int temp = array[i];
                        array[i] = array[i + 1];
                        array[i + 1] = temp;

                        continueLoop = true;
                    }
                }
                --loops;
            }
        }
    }
}
